//
//  UIBarButtonItem+Extention.swift
//  Weibo
//
//  Created by 李学林 on 15/12/5.
//  Copyright © 2015年 tete. All rights reserved.
//

import UIKit

// item字体大小
let ItemTitleFontSize: CGFloat = 14
// item字体颜色
let ItemTitleColor: UIColor = UIColor(white: 80 / 255, alpha: 1)

extension UIBarButtonItem{

    convenience init(imageName: String? = nil, title: String? = nil , target: AnyObject?, action: Selector) {
        
        self.init()
        
        let button: UIButton = UIButton()
        
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let img = imageName {
        
        button.setImage(UIImage(named: img), forState: .Normal)
            button.setImage(UIImage(named: "\(img)_highlighted"), forState: .Highlighted)
        
        }
        
        if let tit = title {
        
            button.setTitle(tit, forState: .Normal)
            button.setTitleColor(ItemTitleColor, forState: .Normal)
        
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            button.titleLabel?.font = UIFont.systemFontOfSize(ItemTitleFontSize)
        }
        
        button.sizeToFit()
        
        customView = button;
    }

    






}

